<?php
/**
 * Created by PhpStorm.
 * User: yuguozhen
 * Date: 16/7/15
 * Time: 下午3:07
 */
define('CLI_PATH', dirname(__DIR__).DIRECTORY_SEPARATOR);
class WrConsoleLoader{

    static function loadClass($className){
        $file = str_replace('\\', '/', $className);


        if( self::isModel($className) ){
            $file = str_replace('Model', '', $file);
        }elseif ( self::isExtension($className) ){
            $file = $file.'.class';
        }elseif ( self::isPlugin($className) ){
            $file = $file.'.class';
        }

        $file = CLI_PATH.$file.'.php';

        if(file_exists($file)) {
            include $file;
        }else{
            echo "no-".$file."\n";
        }
    }

    private static function isModel($className){
        return is_numeric(stripos($className, 'models')) ? true : false;
    }

    private static function isExtension($className){
        return is_numeric(stripos($className, 'extension')) ? true : false;
    }

    public static function isPlugin($className){
        return is_numeric(stripos($className, 'plugin')) ? true : false;
    }
}

spl_autoload_register(['WrConsoleLoader','loadClass']);
